/**
*  Class describing a basic cancel ok frame
*
*  @copyright 2016
*/

/**
*  Dependencies
*/
#include "confirmframe.h"

/**
*  Set up namespace
*/
namespace AMQP{

/**
*  Class implementation
*/
class ConfirmSelectOKFrame : public ConfirmFrame
{
protected:
	/**
	* Encode a frame on a string buffer
	*
	* @param   buffer  buffer to write frame to
	*/
	virtual void fill(OutBuffer& buffer) const override
	{
		// call base
		ConfirmFrame::fill(buffer);
	}

public:
	/**
	*  Construct a confirm select ok frame
	*
	*  @param  frame   received frame
	*/
	ConfirmSelectOKFrame(ReceivedFrame &frame) :
		ConfirmFrame(frame)
	{}

	/**
	*  Construct a confirm select ok frame (client-side)
	*  @param  channel     channel identifier
	*/
	ConfirmSelectOKFrame(uint16_t channel) :
		ConfirmFrame(channel, 0)
	{}

	/**
	*  Destructor
	*/
	virtual ~ConfirmSelectOKFrame() {}

	/**
	*  Return the method ID
	*  @return uint16_t
	*/
	virtual uint16_t methodID() const override
	{
		return 11;
	}

	/**
	*  Process the frame
	*  @param  connection      The connection over which it was received
	*  @return bool            Was it succesfully processed?
	*/
	virtual bool process(std::shared_ptr<ConnectionImpl> connection) override
	{
		// we need the appropriate channel
		auto channel = connection->channel(this->channel());

		// channel does not exist
		if (!channel) return false;

		// report
		if (channel->reportSuccess()) channel->onSynchronized();

		// done
		return true;
	}
};

/**
*  End of namespace
*/
}